package day14;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChatServer {
    public static void main(String[] args) throws IOException {
        ServerSocket st=new ServerSocket(9999);
        while (true){
            Socket s = st.accept();
            System.out.println(s+"连接了");
            System.out.println(s.getPort()+" ????");
            InputStream in = s.getInputStream();
            OutputStream out = s.getOutputStream();
            PrintWriter pw=new PrintWriter(out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(in));
            //阻塞式IO。。。newio:nio=> AIO=>
            //客户端发，服务端回复的
            while (true){
                String ques=br.readLine();//  ，认为说完了。。。
                String answer="朕知道了："+ques+",等消息";
                pw.println(answer);
                if(ques.equals("exit"))
                    break;
            }
            s.close();

        }
    }
}
